<?php
// +----------------------------------------------------------------------
// | saiadmin [ saiadmin快速开发框架 ]
// +----------------------------------------------------------------------
// | Author: your name
// +----------------------------------------------------------------------
namespace app\financeInstitution\logic;

use plugin\saiadmin\basic\BaseLogic;
use plugin\saiadmin\exception\ApiException;
use plugin\saiadmin\utils\Helper;
use app\financeInstitution\model\financeInstitution;
use plugin\saiadmin\service\OpenSpoutWriter;

/**
 * 机构列表逻辑层
 */
class financeInstitutionLogic extends BaseLogic
{
    /**
     * 构造函数
     */
    public function __construct()
    {
        $this->model = new financeInstitution();
    }
public function export($where = [])
{
    $query = $this->search($where);
    // ->field('id,name,enterprise_id,sort,status,create_time');
    $data = $this->getAll($query);
    // var_dump($data);exit();

    
    $file_name = '金融机构数据.xlsx';
    $header = ['logo', '联系人', '联系电话', '是否置顶', '金融机构名称', '金融分类', '机构介绍','创建时间'];
    
    $filter = [
       
    ];
    $data_attr = [];
    foreach ($data as $value) {
        $data_attr[] = [
            'institution_logo' => $value['institution_logo'],
            'contact_person' => $value['contact_person'],
            'contact_number' => $value['contact_number'],
            'is_display_text' => $value['is_display']?'展示':'下架',
            'institution_name' => $value['institution_name'],
            'finance_category_text' => $value['finance_category_text'],
            'institution_intro' => $value['institution_intro'],
            'create_time' => $value['create_time']
        ];
    }

    $writer = new OpenSpoutWriter($file_name);
    $writer->setWidth([20, 20, 20, 20, 20, 20, 50,20]);
    $writer->setHeader($header);
    $writer->setData($data_attr, null, $filter);
    $file_path = $writer->returnFile();
    return response()->download($file_path, urlencode($file_name));
}


}
